package model

type User struct {
	Name  string
	Age   int
	Hobby map[int]string
}

type UserOptionFunc func(*User)

type UserOptionFuncs []UserOptionFunc

func (this *UserOptionFuncs) apply(u *User) {
	for _, v := range *this {
		v(u)
	}
}

func WithName(name string) UserOptionFunc {
	return func(u *User) {
		u.Name = name
	}
}

func WithAge(age int) UserOptionFunc {
	return func(u *User) {
		u.Age = age
	}
}
func WithHobby(hobbies map[int]string) UserOptionFunc {
	return func(u *User) {
		u.Hobby = hobbies
	}
}

func NewUser(opts ...UserOptionFunc) *User {
	u := new(User)
	optfs := UserOptionFuncs(opts)

	optfs.apply(u)
	return u
}
